import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path, { resolve } from 'path'
import setupExtend from 'vite-plugin-vue-setup-extend'
import autoImport from 'unplugin-auto-import/vite'

const createAutoImport = function () {
    return autoImport({
        imports: ['vue', 'vue-router'],
        dts: false
    })
}

export default defineConfig({
    plugins: [
        vue(),
        createAutoImport(),
        setupExtend()
    ],
    resolve: {
        alias: {
            // 设置路径
            '~': path.resolve(__dirname, './'),
            // 设置 别名
            '@': path.resolve(__dirname, './src')
        }
    },
    server: {
        port: 3100,
        host: true,
        open: false,
        proxy: {
            '/dis/': {
                target: 'http://192.168.110.198:4001/dis',
                changeOrigin: true,
                ws: true,
                rewrite: (p) => p.replace(/^\/dis/, '')
            }
        }
    },
    base: '/',
    css: {
        preprocessorOptions: {
            scss: {
                additionalData:
                    '@use "./src/style/common.scss" as *;@use "./src/style/variables.scss" as *;'
            }
        }
    },
    build: {
        emptyOutDir: false,
        rollupOptions: {
            input: {
                default: resolve(__dirname, 'index.html')
            }
        }
    }
})
